<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js" type="text/javascript"></script>
  <style>

  </style>
</head>

<body>
  <div id='root'>

    <button-counter></button-counter>

    <button-counter></button-counter>

    <button-counter></button-counter>

    <button-counter></button-counter>

    <button-counter></button-counter>

    <div>
      <a-container></a-container>
    </div>
  </div>

  <script>
    // * 局部注册组件
    let headera = {
      data: function () {
        return {
          msg: '头部信息'
        }
      },
      template: `
            <div>
                <div>{{ msg }}</div>
                <div class="header">我是头部</div>
            </div>
            `,
      methods: {

      }
    }

    // * 一个组件就是一个Vue实例
    // * 全局注册一个Vue组件
    // * 组件名
    // * 组件内容
    // * 组件自己管理自己的状态
    Vue.component('button-counter', {
      // * 在vue2.0，组件都是单根
      template: `<div>
                        <button @click='add'>click me {{count}} times</button>
                      </div>`,
      // * 局部注册组件
      components: {

      },
      data() {
        return {
          count: 0
        }
      },
      methods: {
        add() {
          this.count++;
        }
      }
    })

    Vue.component('a-container', {
      template: `<div><headera></headera>我是a组件</div>`,
      components: {
        headera
      }
    })

    let vm = new Vue({
      el: '#root',
      // * 局部注册组件
      // components:{
      //     headerb :  headera
      // },
      data: function () {
        return {
          a: 1
        }
      },
      methods: {

      },
      computed: {

      }
    })

  </script>
</body>

</html>
